package com.clstu.leetcode;

import java.util.TreeMap;

/**
 * 探究TreeMap 有序表的使用
 */
public class TreeMapDemo {
    public static void main(String[] args) {
        TreeMap<Integer,String> treeMap = new TreeMap<>();
        treeMap.put(1,"hello");
        treeMap.put(5,"good");
        treeMap.put(39,"hh");

        StringBuilder stringBuilder = new StringBuilder();
        char[] s = "hello".toCharArray();
        String regStr = new String(s);
        System.out.println(regStr+" dfadfa");
        stringBuilder.append("hello");
        stringBuilder.delete(0,2);

        //所有操作时间复杂度 O(logN)级别 非常快

        //特殊操作!!! 特定情况下非常方便 floor ceiling

        System.out.println(treeMap.floorKey(6));//返回<=6的最大key
        System.out.println(treeMap.ceilingKey(4));//返回>=4的最小key
        Integer ceiling = treeMap.ceilingKey(40);
        System.out.println(treeMap.ceilingEntry(4).getValue());
        System.out.println(ceiling);//null
    }
}
